package com.test.controller;

import com.test.domain.Result;
import com.test.domain.User;
import com.test.domain.Utils;
import com.test.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/customer")
public class CustomerController {

    private final CustomerService customerService;

    @Autowired
    public CustomerController(CustomerService customerService) {
        this.customerService = customerService;
    }

    @GetMapping("/info")
    public Result getInfo(@RequestParam("phoneNumber") String phoneNumber){
        System.out.println(phoneNumber);
        return Utils.success(customerService.customerInfo(phoneNumber));
    }

    @PostMapping("/login")
    public Result login(@RequestBody User user){
        System.out.println(user);
        int status  = customerService.registerAndLogin(user);
        return Utils.success(status);
    }

    @GetMapping("/getShopListByKeyword")
    public Result getShopListByKeyword(@RequestParam("keyword")String keyword){
        return Utils.success(customerService.getShopListByKeyword(keyword));
    }

    @GetMapping("/getRecommend")
    public Result getRecommend(){
        return Utils.success(customerService.getShopList());
    }




}
